<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/demo.js"></script>

    <!-- 等价于 -->
    <!-- <script>
        var box = document.getElementsByClassName("box")[0]; // [][0] => undefind
        box.onclick = function () {
            alert(111111);
        }
    </script> -->

    <style>
        * {
            padding: 0;
            margin: 0;
        }
    </style>
</head>

<body>
    <a href="https://www.baidu.com">跳转百度</a>
</body>
<script>


    // onfocus 窗口聚焦(从其他页面/窗口切到当前窗口)
    // onblur  窗口失焦(从当前窗口切到其他页面/窗口)

    // var count = 0;
    // window.onfocus = function () {
    //     console.log(1111);
    //     document.body.innerText = "欢迎光临" + (count == 0 ? "" : count);
    //     document.body.style.fontSize = "40px";
    //     document.body.style.textAlign = "center";
    //     document.body.style.backgroundColor = "pink";
    // }

    // window.onblur = function () {
    //     count++;
    //     // window.close()
    // }

    // 页面离开之前触发  => 页面跳转,关闭窗口,刷新页面
    // window.onbeforeunload = function () {
    //     return false;
    // }






</script>

</html>